<?php

class MainView {
	
	public $user;
	public $content;
	public $tab;
	public $messages = array();
	
	/**
	 * $user is the currently logged in user (can be null)
	 * $content is a php file (end with .php) or plain html to include
	 * $messages is a list of messages to display to the user, at the top of the window.
	 */
	public function __construct($user, $content, $tab='home') {
		$this->user = $user;
		$this->content = $content;
		$this->tab = $tab;
	}
	
	public function add_message($message) {
		$this->messages[] = $message;
	}
	
	public function send() {
		$view = $this;
		require 'main.php';
	}
}

class StartView extends MainView {
	public $challenge_id;
	public $challenge;
	
	public function __construct($challenge_id, $challenge) {
		parent::__construct(null, "start.php");
		$this->challenge_id = $challenge_id;
		$this->challenge = $challenge;
	}
}

class TandemTabsView extends MainView {
	
	const ACTION_VIEW_MATCHING = 'Match results';
	const ACTION_EDIT_CRITERIA = 'Match criteria';
	const ACTION_EDIT_PROFILE = 'Profile &amp; preferences';
	
	/**
	 * If tabcontent ends with .php, the file will be included, otherwide tabcontent 
	 * will be included right away.
	 */
	public $tabcontent;
	public $tabs;
	public $active_tab;
	
	public function __construct($tabcontent, $active_tab=TandemTabsView::ACTION_VIEW_MATCHING) {
		parent::__construct($_SESSION['user'], "tandem_tabs.php");
		$this->tabcontent = $tabcontent;
		$this->tabs = array(
			TandemTabsView::ACTION_VIEW_MATCHING => new ViewMatchingAction(), 
			TandemTabsView::ACTION_EDIT_CRITERIA => new EditCriteriaAction(), 
			TandemTabsView::ACTION_EDIT_PROFILE => new EditProfileAction(),
		);
		$this->active_tab = $active_tab;
	}
}

class ViewMatchingView extends TandemTabsView {
	public $matches;
	public function __construct($matches) {
		parent::__construct("view_matching.php");
		$this->matches = $matches;
	}
}

class EditCriteriaView extends TandemTabsView {
	public function __construct() {
		parent::__construct("edit_criteria.php", TandemTabsView::ACTION_EDIT_CRITERIA);
	}
}

class EditProfileView extends TandemTabsView {
	public $user;
	public function __construct($user) {
		parent::__construct("edit_profile.php", TandemTabsView::ACTION_EDIT_PROFILE);
		$this->user = $user;
	}
}

class SignoffAskConfirmView extends TandemTabsView {
	public function __construct() {
		parent::__construct("signoff_ask_confirm.php", TandemTabsView::ACTION_EDIT_PROFILE);
	}
}

class ContinueSignupView extends MainView {
	
	public $secret;
	public $name;
	public $email;
	public $user;
	public $recaptcha_error;
	
	public function __construct($secret, $name, $user=null, $recaptcha_error=null) {
		// No user yet -> null
		parent::__construct(null, "continue_signup.php");
		$this->secret = $secret;
		$this->name = $name;
		$this->user = $user;
		$this->recaptcha_error = $recaptcha_error;
	}
	
}

class EditPasswordView extends TandemTabsView {
	
	public $challenge_id;
	public $challenge;
	
	public function __construct($challenge_id, $challenge) {
		parent::__construct("edit_password.php", TandemTabsView::ACTION_EDIT_PROFILE);
		$this->challenge_id = $challenge_id;
		$this->challenge = $challenge;
	}
}

class TryResetPasswordView extends MainView {
	
	public $secret;
	
	public function __construct($secret) {
		parent::__construct(null, "try_reset_password.php");
		$this->secret = $secret;
	}
}

class AdminView extends MainView {
	
	public $users;
	public $messages_sent;
	public $newsletter_addresses;
	public $statistics;
	
	public function __construct($admin, $users, $messages_sent, $newsletter_addresses, $statistics) {
		// user is admin and doesn't matter
		parent::__construct($admin, 'admin.php');
		$this->users = $users;
		$this->messages_sent = $messages_sent;
		$this->newsletter_addresses = $newsletter_addresses;
		$this->statistics = $statistics;
	}
}

?>